﻿using GN.Pay.TradeChannel.ProtocolPay;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GN.Pay.TradeChannel.Gyb.Request
{
    /// <summary>
    /// 协议基本请求
    /// </summary>
    [Serializable]
    abstract class ProtocolBaseRequest : ARequest
    {
        protected readonly IChannel Channel;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="channel"></param>
        /// <param name="apply"></param>
        /// <param name="config"></param>
        protected ProtocolBaseRequest(IChannel channel,
           IProtocolBindApply apply,
           GybConfigure config) : base(config)
        {
            if (channel == null)
            {
                Utils.ExceptionUtils.CheckNotNull(channel, nameof(channel));
            }
            if (apply == null)
            {
                channel.ThrowChannelValidationException("请求的 apply 为 null");
            }
            if (config == null)
            {
                channel.ThrowChannelValidationException("请求的 config 为 null");
            }
            if (config.ConfigureInfo == null)
            {
                channel.ThrowChannelValidationException("请求的 config 的 ConfigureInfo 为 null");
            }
            this.Channel = channel;
            this.TermCode = config.ConfigureInfo.TermCode;
            if (string.IsNullOrWhiteSpace(this.TermCode))
            {
                this.TermCode = "00000000";
            }
            this.MemberNo = apply.MemberId;
            this.IdNo = apply.IdentityNo;
            this.AcctType = "1";
            this.AcctNo = apply.AccountNo;
            this.AcctName = apply.AccountName;
            this.TelPhone = apply.MobilePhone;
        }

        /// <summary>
        /// 终端号,可以全为0
        /// </summary>
        public string TermCode { get; private set; }

        /// <summary>
        /// 会员编号
        /// </summary>
        public string MemberNo { get; private set; }

        /// <summary>
        /// 身份证号
        /// </summary>
        public string IdNo { get; private set; }

        /// <summary>
        /// 账户类型(值 = 1)
        /// </summary>
        public string AcctType { get; private set; }

        /// <summary>
        /// 卡号
        /// </summary>
        public string AcctNo { get; private set; }

        /// <summary>
        /// 户名
        /// </summary>
        public string AcctName { get; private set; }

        /// <summary>
        /// 手机号
        /// </summary>
        public string TelPhone { get; private set; }
    }
}
